package domain

type RepoError int

const (
	DatabaseError           RepoError = 200
	DatabaseCreateError     RepoError = 201
	DatabaseUpdateError     RepoError = 202
	DatabaseDeleteError     RepoError = 203
	DatabaseGetError        RepoError = 204
	DatabaseTXBeginError    RepoError = 205
	DatabaseTXRollbackError RepoError = 206
	DatabaseTXCommitError   RepoError = 207
	DatabaseLockError       RepoError = 208
	DatabaseLocked          RepoError = 209

	CacheError          RepoError = 300
	CacheMakeError      RepoError = 301
	CacheGetError       RepoError = 302
	CacheDeleteError    RepoError = 303
	CacheLocked         RepoError = 304
	CacheLockError      RepoError = 305
	CacheSetExpireError RepoError = 306

	IsExist            RepoError = 401
	NotExist           RepoError = 402
	Disable            RepoError = 403
	MarshalJsonError   RepoError = 404
	UnmarshalJsonError RepoError = 405
)

// RuleStatus 规则状态, 避免拼写错误
const (
	StatusEnabled = "enabled"
	StatusDisable = "disable"
	StatusDeleted = "deleted"

	CacheNullValue = "null"
)

func (e RepoError) Error() string {
	switch e {
	case DatabaseError:
		return "database error"
	case DatabaseCreateError:
		return "database create error"
	case DatabaseUpdateError:
		return "database update error"
	case DatabaseDeleteError:
		return "database delete error"
	case DatabaseGetError:
		return "database get error"
	case DatabaseTXBeginError:
		return "database transaction begin error"
	case DatabaseTXRollbackError:
		return "database transaction rollback error"
	case DatabaseTXCommitError:
		return "database transaction commit error"
	case DatabaseLockError:
		return "database lock error"
	case DatabaseLocked:
		return "database locked"
	case CacheError:
		return "Cache error"
	case CacheMakeError:
		return "Cache make error"
	case CacheGetError:
		return "Cache get error"
	case CacheDeleteError:
		return "Cache delete error"
	case CacheLocked:
		return "Cache locked"
	case CacheLockError:
		return "Cache lock error"
	case CacheSetExpireError:
		return "Cache set expire error"
	case IsExist:
		return "rule is exist"
	case NotExist:
		return "rule is not exist"
	case Disable:
		return "rule is disable"
	case MarshalJsonError:
		return "marshal json error"
	case UnmarshalJsonError:
		return "unmarshal json error"
	default:
		return ""
	}
}
